package cn.fl.ref.scmbaseinfo.controller;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.ref.crbaseinfo.service.ICrBaseInfoService;
import cn.fl.ref.crbaseinfo.vo.CrAstRltvInfoVO;
import cn.fl.ref.crbaseinfo.vo.CrBaseInfoVO;
import cn.fl.ref.fribaseinfo.service.IFriBaseInfoService;
import cn.fl.ref.fribaseinfo.vo.FriBaseInfoVO;
import cn.fl.ref.scmbaseinfo.service.IScmBaseInfoService;
import cn.fl.ref.scmbaseinfo.transform.ScmBaseInfoVOTransform;
import cn.fl.ref.scmbaseinfo.vo.ScmBaseInfoVO;
import cn.fl.ref.scmbaseinfo.vo.ScmChrgParaVO;
import cn.fl.system.constant.SysLogConstant;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.FlowStartParamsDTO;
import fl.flow.facade.flow.dto.FlowStartedDTO;
import fl.ref.crbaseinfo.condition.CrBaseInfoQueryCondition;
import fl.ref.crbaseinfo.constant.CrBaseInfoConstant;
import fl.ref.fncprjbscinfo.constant.FncPrjBaseInfoConstant;
import fl.ref.fribaseinfo.constant.FriBaseInfoConstant;
import fl.ref.scmbaseinfo.condition.ScmBaseInfoQueryCondition;
import fl.ref.scmbaseinfo.constant.ScmInfoConstant;
import fl.ref.scmbaseinfo.constant.ScmInfoConstant.ScmSt;
import fl.ref.scmbaseinfo.dto.ScmBscInfoDTO;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Controller
@RequestMapping("/rfbase/scmbaseinfo")
public class ScmBaseInfoController {
	private static final Logger logger = LoggerFactory.getLogger(ScmBaseInfoController.class);
	
	@Autowired
	private IScmBaseInfoService scmBaseInfoService;

	@Autowired
	private ICrBaseInfoService crBaseInfoService;

	@Autowired
	IFriBaseInfoService friBaseInfoService;
	/**
	 * 本地数据字典服务
	 */
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;

	/**
	 * 跳转到列表页面，初始化参数
	 */
	@RequestMapping(value = "/toListPage.do", method = { RequestMethod.GET })
	public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView view = new ModelAndView("rfbase/scmbaseinfo/scmBaseInfoList");
		String fncInsId  = request.getParameter("fncInsId");
		String fncInsNm="";
		if (StringUtils.isNotEmpty(fncInsId)) {
			FriBaseInfoVO friBaseInfoVO = this.friBaseInfoService.selectById(Long.valueOf(fncInsId), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
			fncInsNm  = friBaseInfoVO.getFundRasInsNm();
		}
		List<KeyValueVO> rePyTpCdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_REPY_TP, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//还款类别
		List<KeyValueVO> fncCrdnltCdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_FNC_CRDNLT, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//融资基数
		List<KeyValueVO> fncScmStCdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_SCM_ST, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//方案状态
		view.addObject("rePyTpCdLst", rePyTpCdLst);
		view.addObject("fncCrdnltCdLst", fncCrdnltCdLst);
		view.addObject("fncScmStCdLst", fncScmStCdLst);
		view.addObject("fncInsNm", fncInsNm);
		view.addObject("fncInsId", fncInsId);
		BaseLogUtils.info(logger, "toListPage", "查询数据完成. DATA:" + (fncInsId), CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	/**
	 * 跳转到新增页面
	 * @param request
	 * @param response
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	@RequestMapping(value = "/toAddPage.do")
	public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException{
		ModelAndView view = new ModelAndView("rfbase/scmbaseinfo/scmBaseInfoAdd");
		String fncInsId = request.getParameter("fncInsId");
		FriBaseInfoVO friBaseInfoVO = friBaseInfoService.selectById(Long.parseLong(fncInsId), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
		String fncInsNm  = friBaseInfoVO.getFundRasInsNm();
		Integer abs = friBaseInfoVO.getIsAbs();
		List<KeyValueVO> rePyTpCdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_REPY_TP, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//还款类别
		List<KeyValueVO> fncCrdnltCdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_FNC_CRDNLT, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//融资基数
		List<KeyValueVO> fncScmStCdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_SCM_ST, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//方案状态
		List<KeyValueVO> prymMtdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_PRYM_MTD, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//调息方式
		List<KeyValueVO> mrgnClCrdnltLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_MRGN_CL_CRDNLT, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//保证金计算基数
		List<KeyValueVO> costCrdnltLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_CHRG_PARM_COST_CRDNLT, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//费用基数
		List<KeyValueVO> chrgTpCdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_CHRG_PARM_CHRG_TPCD, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//计费类型
		List<KeyValueVO> mrgnUseMtdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_CHRG_PARM_MRGN_USE_MTD, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//保证金使用方式
		List<KeyValueVO> busTypeLst = sysDictionaryApiService.getKvList(FncPrjBaseInfoConstant.FNC_PRJ_BSC_INFO_BUS_TYPE, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//业务类型
		List<KeyValueVO> intrtMtdcdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_INTRT_MTDCD, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//利率浮动方式代码//
		List<KeyValueVO> guaranteeBodyLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_GUARANTEE_BODY, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//担保主体 add by gengchunlan 20191018
		List<KeyValueVO> sysList = sysDictionaryApiService.getKvList(ScmInfoConstant.SYS0021, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//是否 add by gengchunlan 20191021
		
		List<KeyValueVO> feeList = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_FEE, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//费用名称
		
		List<KeyValueVO> searchWthrKVList = scmBaseInfoService.searchWthrKVList();//是否标志
		List<KeyValueVO> searchWthrKVListBZJ = scmBaseInfoService.searchWthrKVListBZJ();//保证金是否坐扣2018-04-27
		view.addObject("rePyTpCdLst", rePyTpCdLst);
		view.addObject("fncCrdnltCdLst", fncCrdnltCdLst);
		view.addObject("fncScmStCdLst", fncScmStCdLst);
		view.addObject("prymMtdLst", prymMtdLst);
		view.addObject("mrgnClCrdnltLst", mrgnClCrdnltLst);
		view.addObject("costCrdnltLst", costCrdnltLst);
		view.addObject("chrgTpCdLst", chrgTpCdLst);	
		view.addObject("searchWthrKVList", searchWthrKVList);
		view.addObject("searchWthrKVListbzj", searchWthrKVListBZJ);
		view.addObject("fncInsId", fncInsId);
		view.addObject("fncInsNm", fncInsNm);
		view.addObject("abs", abs);
		view.addObject("mrgnUseMtdLst", mrgnUseMtdLst);
		view.addObject("mrgnUseMtdJSON", com.alibaba.fastjson.JSONObject.toJSONString(mrgnUseMtdLst));//add by gengchunlan 20180706
		view.addObject("busTypeLst", busTypeLst);
		view.addObject("intrtMtdcdLst", intrtMtdcdLst);//
		view.addObject("guaranteeBodyLst", JSON.toJSONString(guaranteeBodyLst));//担保主体 add by gengchunlan 20191018
		view.addObject("sysYNList",sysList);//是 否 add by gengchunlan 20191021
		view.addObject("feeList",feeList);
		BaseLogUtils.info(logger, "toAddPage", "查询数据完成. DATA:" + (fncInsId), CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	/**
	 * 到详情页面
	 */
	@RequestMapping(value = "/toDetail.do", method = { RequestMethod.GET, RequestMethod.POST })
	public ModelAndView scmBaseInfoService(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String isFlow = request.getParameter("isFlow");//是否流程附加信息页面标识
		BaseLogUtils.info(logger, "toDetail", "加载融资方案详情页面.",CurrentThreadContext.getCurrentUserName());
		ModelAndView view = new ModelAndView("rfbase/scmbaseinfo/scmBaseInfoDetail");
		ScmBaseInfoVO bscinfo = scmBaseInfoService.selectById(Long.parseLong(id));
		FriBaseInfoVO friBaseInfoVO = friBaseInfoService.selectById(bscinfo.getFncInsId(), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
		String fncInsNm  = friBaseInfoVO.getFundRasInsNm();
		List<KeyValueVO> rePyTpCdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_REPY_TP, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//还款类别
		List<KeyValueVO> fncCrdnltCdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_FNC_CRDNLT, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//融资基数
		List<KeyValueVO> fncScmStCdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_SCM_ST, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//方案状态
		List<KeyValueVO> prymMtdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_PRYM_MTD, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//调息方式
		List<KeyValueVO> mrgnClCrdnltLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_MRGN_CL_CRDNLT, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//保证金计算基数
		List<KeyValueVO> costCrdnltLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_CHRG_PARM_COST_CRDNLT, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//费用基数
		List<KeyValueVO> chrgTpCdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_CHRG_PARM_CHRG_TPCD, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//计费类型
		List<KeyValueVO> mrgnUseMtdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_CHRG_PARM_MRGN_USE_MTD, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//保证金使用方式
		List<KeyValueVO> busTypeLst = sysDictionaryApiService.getKvList(FncPrjBaseInfoConstant.FNC_PRJ_BSC_INFO_BUS_TYPE, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//业务类型
		List<KeyValueVO> intrtMtdcdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_INTRT_MTDCD, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//利率浮动方式代码//
		List<KeyValueVO> guaranteeBodyLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_GUARANTEE_BODY, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//担保主体 add by gengchunlan 20191018
		List<KeyValueVO> sysList = sysDictionaryApiService.getKvList(ScmInfoConstant.SYS0021, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//是否 add by gengchunlan 20191021
		List<KeyValueVO> feeList = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_FEE, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//费用名称
		
		List<KeyValueVO> searchWthrKVList = scmBaseInfoService.searchWthrKVList();//是否标志
		List<KeyValueVO> searchWthrKVListbzj = scmBaseInfoService.searchWthrKVListBZJ();//保证金是否坐扣
		if(bscinfo.getCrId() != null && !bscinfo.getCrId().trim().equals("")){
			CrBaseInfoVO crBaseInfoVO = scmBaseInfoService.selectByCrId(bscinfo.getCrId());
			List<CrAstRltvInfoVO> lst = crBaseInfoVO.getCrAstRltvInfoListVO();
			String pdNm = "";
			for(CrAstRltvInfoVO ccvo : lst){
				if(ccvo.getHid()!=null && ccvo.getHid().equals(bscinfo.getPdId())){
					pdNm = ccvo.getPdNm();
				}
			}
			view.addObject("crNm", crBaseInfoVO.getCrNm());
			view.addObject("pdNm", pdNm);
		}
		view.addObject("bscinfo", bscinfo);
		view.addObject("fncScmId", id);
		view.addObject("fncInsNm", fncInsNm);
		view.addObject("isFlow", isFlow);
		view.addObject("busTypeLst", busTypeLst);
		view.addObject("rePyTpCdLst", rePyTpCdLst);
		view.addObject("fncCrdnltCdLst", fncCrdnltCdLst);
		view.addObject("fncScmStCdLst", fncScmStCdLst);
		view.addObject("prymMtdLst", prymMtdLst);
		view.addObject("mrgnClCrdnltLst", mrgnClCrdnltLst);
		view.addObject("costCrdnltLst", costCrdnltLst);
		view.addObject("chrgTpCdLst", chrgTpCdLst);	
		view.addObject("searchWthrKVList", searchWthrKVList);
		view.addObject("searchWthrKVListbzj", searchWthrKVListbzj);
		view.addObject("mrgnUseMtdLst", mrgnUseMtdLst);
		view.addObject("mrgnUseMtdJSON", com.alibaba.fastjson.JSONObject.toJSONString(mrgnUseMtdLst));//add by gengchunlan 20180706
		view.addObject("feeListJSON", com.alibaba.fastjson.JSONObject.toJSONString(feeList));//add by gengchunlan 20180706
		
		view.addObject("intrtMtdcdLst", intrtMtdcdLst);//
		view.addObject("guaranteeBodyLst", JSON.toJSONString(guaranteeBodyLst));//担保主体 add by gengchunlan 20191018
		view.addObject("sysYNList",sysList);//是否 add by gengchunlan 20191021
		BaseLogUtils.info(logger, "scmBaseInfoService", "查询数据完成. DATA:" + (id), CurrentThreadContext.getCurrentUserName());
		return view;
	}
	
	/**
	 * 跳转到修改页面
	 * @param request
	 * @param response
	 * @return
	 * @throws UnsupportedEncodingException 
	 */
	@RequestMapping(value = "/toModifyPage.do")
	public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException{
		ModelAndView view = new ModelAndView("rfbase/scmbaseinfo/scmBaseInfoModify");
		String fncScmId = request.getParameter("fncScmId");
		List<KeyValueVO> rePyTpCdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_REPY_TP, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//还款类别
		List<KeyValueVO> fncCrdnltCdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_FNC_CRDNLT, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//融资基数
		List<KeyValueVO> fncScmStCdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_SCM_ST, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//方案状态
		List<KeyValueVO> prymMtdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_PRYM_MTD, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//调息方式
		List<KeyValueVO> mrgnClCrdnltLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_MRGN_CL_CRDNLT, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//保证金计算基数
		List<KeyValueVO> costCrdnltLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_CHRG_PARM_COST_CRDNLT, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//费用基数
		List<KeyValueVO> chrgTpCdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_CHRG_PARM_CHRG_TPCD, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//计费类型
		List<KeyValueVO> mrgnUseMtdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_CHRG_PARM_MRGN_USE_MTD, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//保证金使用方式
		List<KeyValueVO> busTypeLst = sysDictionaryApiService.getKvList(FncPrjBaseInfoConstant.FNC_PRJ_BSC_INFO_BUS_TYPE, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//业务类型
		List<KeyValueVO> intrtMtdcdLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_BSC_INFO_INTRT_MTDCD, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//利率浮动方式代码//
		List<KeyValueVO> guaranteeBodyLst = friBaseInfoService.getKvList(ScmInfoConstant.FNC_SCM_GUARANTEE_BODY);//担保主体 add by gengchunlan 20191018
		List<KeyValueVO> sysList = sysDictionaryApiService.getKvList(ScmInfoConstant.SYS0021, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//是否 add by gengchunlan 20191021
		List<KeyValueVO> feeList = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_FEE, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//费用名称
		
		List<KeyValueVO> searchWthrKVList = scmBaseInfoService.searchWthrKVList();//是否标志
		List<KeyValueVO> searchWthrKVListbzj = scmBaseInfoService.searchWthrKVListBZJ();//保证金是否坐扣
		ScmBaseInfoVO bscinfo = scmBaseInfoService.selectById(Long.parseLong(fncScmId));
		FriBaseInfoVO friBaseInfoVO = friBaseInfoService.selectById(bscinfo.getFncInsId(), CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
		String fncInsNm  = friBaseInfoVO.getFundRasInsNm();
		Integer abs = friBaseInfoVO.getIsAbs();
		if(bscinfo.getCrId() != null && !bscinfo.getCrId().trim().equals("")){
			CrBaseInfoVO crBaseInfoVO = scmBaseInfoService.selectByCrId(bscinfo.getCrId());
			List<CrAstRltvInfoVO> lst = crBaseInfoVO.getCrAstRltvInfoListVO();
			String pdNm = "";
			for(CrAstRltvInfoVO ccvo : lst){
				if(ccvo.getHid()!=null && ccvo.getHid().equals(bscinfo.getPdId())){
					pdNm = ccvo.getPdNm();
				}
			}
			view.addObject("crNm", crBaseInfoVO.getCrNm());
			view.addObject("pdNm", pdNm);
		}
		view.addObject("rePyTpCdLst", rePyTpCdLst);
		view.addObject("fncCrdnltCdLst", fncCrdnltCdLst);
		view.addObject("fncScmStCdLst", fncScmStCdLst);
		view.addObject("prymMtdLst", prymMtdLst);
		view.addObject("mrgnClCrdnltLst", mrgnClCrdnltLst);
		view.addObject("costCrdnltLst", costCrdnltLst);
		view.addObject("chrgTpCdLst", chrgTpCdLst);	
		view.addObject("searchWthrKVList", searchWthrKVList);
		view.addObject("searchWthrKVListbzj", searchWthrKVListbzj);
		view.addObject("mrgnUseMtdLst", mrgnUseMtdLst);
		view.addObject("mrgnUseMtdJSON", com.alibaba.fastjson.JSONObject.toJSONString(mrgnUseMtdLst));//add by gengchunlan 20180706
		view.addObject("feeListJSON", com.alibaba.fastjson.JSONObject.toJSONString(feeList));//add by gengchunlan 20180706
		
		view.addObject("busTypeLst", busTypeLst);
		view.addObject("intrtMtdcdLst", intrtMtdcdLst);//
		view.addObject("bscinfo", bscinfo);
		view.addObject("fncScmId", fncScmId);
		view.addObject("fncInsNm", fncInsNm);
		view.addObject("abs", abs);
		view.addObject("guaranteeBodyLst", JSON.toJSONString(guaranteeBodyLst));//担保主体 add by gengchunlan 20191018
		view.addObject("sysYNList",sysList);//是否 add by gengchunlan 20191021
		BaseLogUtils.info(logger, "toModifyPage", "查询数据完成. DATA:" + (fncScmId), CurrentThreadContext.getCurrentUserName());
		return view;
	}

	private void setScmMapData (List<Map<String, Object>> lstMap,String sysCd, String orgCd){
		if(CollectionUtils.isEmpty(lstMap))return;
		Map<String, String> rePyTpCdMap = sysDictionaryApiService.searchGroupToMap(sysCd, orgCd,ScmInfoConstant.FNC_SCM_BSC_INFO_REPY_TP);//还款类别
		Map<String, String> fncScmStCdMap = sysDictionaryApiService.searchGroupToMap(sysCd, orgCd,ScmInfoConstant.FNC_SCM_BSC_INFO_SCM_ST);//方案状态
		for(Map<String,Object> map:lstMap){
			if(map.get("REPY_TP")!=null){
				map.put("REPY_TP_DES", rePyTpCdMap.get(map.get("REPY_TP").toString()));
			}
			if(map.get("SCM_ST")!=null){
				map.put("SCM_ST_DES", fncScmStCdMap.get(map.get("SCM_ST").toString()));
			}
		}
	}
	
	private void setScmDicData(List<ScmBaseInfoVO> lstVO, String sysCd, String orgCd){
		if(CollectionUtils.isEmpty(lstVO))return;
		Map<String, String> rePyTpCdMap = sysDictionaryApiService.searchGroupToMap(sysCd, orgCd,ScmInfoConstant.FNC_SCM_BSC_INFO_REPY_TP);//还款类别
		Map<String, String> fncCrdnltCdMap = sysDictionaryApiService.searchGroupToMap(sysCd, orgCd,ScmInfoConstant.FNC_SCM_BSC_INFO_FNC_CRDNLT);//融资基数
		Map<String, String> fncScmStCdMap = sysDictionaryApiService.searchGroupToMap(sysCd, orgCd,ScmInfoConstant.FNC_SCM_BSC_INFO_SCM_ST);//方案状态
		for(ScmBaseInfoVO vo : lstVO){
			if(vo.getRepyTp() != null){
				vo.setRepyTpDes(rePyTpCdMap.get(vo.getRepyTp().toString()));
			}
			if(vo.getFncCrdnlt() != null){
				vo.setFncCrdnltDes(fncCrdnltCdMap.get(vo.getFncCrdnlt().toString()));
			}
			if(vo.getScmSt() != null){
				vo.setScmDes(fncScmStCdMap.get(vo.getScmSt().toString()));
			}
			if(vo.getCrId() != null){
				CrBaseInfoVO cvo = crBaseInfoService.selectByCrId(vo.getCrId());
				vo.setCrDes(cvo.getCrNm());
			}
		}
	}
	
	public void setCrDicInfo(List<CrBaseInfoVO> listVO, String sysCd, String orgCd) {
		if(CollectionUtils.isEmpty(listVO))return;
		try {
			Map<String, String> ccytpMap = this.sysDictionaryApiService.searchGroupToMap(sysCd, orgCd, CrBaseInfoConstant.CR_BSC_INFO_CCY_TP);
			Map<String, String> crstMap = this.sysDictionaryApiService.searchGroupToMap(sysCd, orgCd, CrBaseInfoConstant.CR_BSC_INFO_CR_ST);
			Map<String, String> rvlcrMap = this.sysDictionaryApiService.searchGroupToMap(sysCd, orgCd, CrBaseInfoConstant.CR_BSC_INFO_RVL_CR);
			Map<String, String> crsbjMap = this.sysDictionaryApiService.searchGroupToMap(sysCd, orgCd, CrBaseInfoConstant.CR_BSC_INFO_CR_SBJ);
			Map<String, String> astidMap = this.sysDictionaryApiService.searchGroupToMap(sysCd, orgCd, CrBaseInfoConstant.CR_AST_RLTV_AST_ID);
			
			for (CrBaseInfoVO crBaseInfoVO:listVO) {
				if(crBaseInfoVO.getCcyTp()!=null){
					if(ccytpMap.containsKey(crBaseInfoVO.getCcyTp().toString())){
						crBaseInfoVO.setCcyTpNm(ccytpMap.get(crBaseInfoVO.getCcyTp().toString()));
					}
				}
				if(crBaseInfoVO.getCrSt()!=null){
					if(crstMap.containsKey(crBaseInfoVO.getCrSt().toString())){
						crBaseInfoVO.setCrStNm(crstMap.get(crBaseInfoVO.getCrSt().toString()));
					}
				}
				if(crBaseInfoVO.getRvlCr()!=null){
					if(rvlcrMap.containsKey(crBaseInfoVO.getRvlCr().toString())){
						crBaseInfoVO.setRvlCrNm(rvlcrMap.get(crBaseInfoVO.getRvlCr().toString()));
					}
				}
				if(crBaseInfoVO.getCrSbj()!=null){
					String crSbjNm="";
					for (String key : crsbjMap.keySet()) {
						if(crBaseInfoVO.getCrSbj().contains(key)){
							crSbjNm +=crsbjMap.get(key)+"; ";
						}
					 }
					crBaseInfoVO.setCrSbjNm(crSbjNm);
				}
				List<CrAstRltvInfoVO> AstInfoList=crBaseInfoVO.getCrAstRltvInfoListVO();
				if(CollectionUtils.isEmpty(AstInfoList)){
					continue;
				}else{
					List<CrAstRltvInfoVO> AstInfoListnew=new ArrayList<CrAstRltvInfoVO>();
					for (CrAstRltvInfoVO crAstRltvInfoDTO : AstInfoList) {
						if(astidMap.containsKey(crAstRltvInfoDTO.getAstId())){
							crAstRltvInfoDTO.setAstNm(astidMap.get(crAstRltvInfoDTO.getAstId()));
							AstInfoListnew.add(crAstRltvInfoDTO);
						}
					}
					crBaseInfoVO.setCrAstRltvInfoListVO(AstInfoListnew);
				
				}
			}
			
		} catch (Exception e) {
			BaseLogUtils.error(logger, "setDicInfo", "获取DIC数据失败!");
			e.printStackTrace();
		}
	}
	
	/**
	 * 初始化列表
	 * @return
	 */
	@RequestMapping(value="/initList.do" ,method = {RequestMethod.GET})
	public @ResponseBody Map<String, Object>  initList(HttpServletRequest request, HttpServletResponse response) {		
//		{"fncInsNm":"","rePyTpCd":"1","fncCrdnlt":"2","fncScmStcd":"2","fncScmNm":"","crNm":"","fncInsId":""}
		String insid = request.getParameter("fncInsId");
		String fncInsNm = request.getParameter("fncInsNm");

		String rePyTpCd = request.getParameter("rePyTpCd");
		String fncCrdnlt = request.getParameter("fncCrdnlt");
		String fncScmStcd = request.getParameter("fncScmStcd");
		String fncScmNm = request.getParameter("fncScmNm");
		String crNm = request.getParameter("crNm");
		ScmBaseInfoQueryCondition cnd = new ScmBaseInfoQueryCondition();
		if(insid != null && !insid.trim().equals("")){
			cnd.setFncInsId(insid);
		}
		if(StringUtils.isNotEmpty(rePyTpCd)){
			cnd.setRePyTpCd(Integer.parseInt(rePyTpCd));
		}
		if(StringUtils.isNotEmpty(fncCrdnlt)){
			cnd.setFncCrdnlt(Integer.parseInt(fncCrdnlt));
		}
		if(StringUtils.isNotEmpty(fncScmStcd)){
			cnd.setFncScmStcd(Integer.parseInt(fncScmStcd));
		}
		if(StringUtils.isNotEmpty(fncScmNm)){
			cnd.setFncScmNm(fncScmNm);
		}
		if(StringUtils.isNotEmpty(fncInsNm)){
			cnd.setInstNm(fncInsNm);
		}
		if(StringUtils.isNotEmpty(crNm)){
			cnd.setCrNm(crNm);
		}
		cnd.setSysCd(CurrentThreadContext.getCurrentSysCd());
		cnd.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		List<Map<String, Object>> lstMap = scmBaseInfoService.selectBscLstMapByCondition(cnd);
		setScmMapData(lstMap, CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("Rows", lstMap);
		map.put("Total", lstMap.size());
		BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:lstMap" + (lstMap), CurrentThreadContext.getCurrentUserName());
		return map;
	}

	
	/**
	 * 初始化列表2
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value="/initList2.do" ,method = {RequestMethod.GET})
	public @ResponseBody ListPageVO<ScmBaseInfoVO>  initList2(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		String insid = request.getParameter("fncInsId");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(currentPage)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		ScmBaseInfoQueryCondition cnd = new ScmBaseInfoQueryCondition();
		if(insid != null && !insid.trim().equals("")){
			cnd.setFncInsId(insid);
		}
		cnd.setSysCd(CurrentThreadContext.getCurrentSysCd());
		cnd.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
		page.setCondition(cnd);
		Pager pager = scmBaseInfoService.searchListPage(page);
		List<ScmBscInfoDTO> lstDto = (List<ScmBscInfoDTO>)pager.getResultList();
		List<ScmBaseInfoVO> lstVo = ScmBaseInfoVOTransform.toVOList(lstDto);
		setScmDicData(lstVo,CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd());
		ListPageVO<ScmBaseInfoVO> pvo = new ListPageVO<>(lstVo, lstVo.size());
		BaseLogUtils.info(logger, "initList2", "查询数据完成. DATA:insid" + (insid), CurrentThreadContext.getCurrentUserName());
		return pvo;
	}
	
	/**
	 * 初始化授信列表
	 * @return
	 */
	@RequestMapping(value="/initCrList.do" ,method = {RequestMethod.GET})
	public @ResponseBody List<CrBaseInfoVO> initCrList(HttpServletRequest request, HttpServletResponse response) {
		String insId = request.getParameter("insId");
		if(insId==null){
			insId = "-1";
		}
		CrBaseInfoQueryCondition qc = new CrBaseInfoQueryCondition();
		qc.setFncInsIdQ(Long.valueOf(insId));
		qc.setCrStQ(1);
		List<CrBaseInfoVO> lst = crBaseInfoService.selectByCondition(qc);
		//筛选余额大于0
		for (int i = 0; i < lst.size(); i++) {
			if (lst.get(i).getCrBal()==null||lst.get(i).getCrBal().doubleValue()>0) {
				
			}else {
				lst.remove(i);
				i--;
			}
		}		
		setCrDicInfo(lst,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
		BaseLogUtils.info(logger, "initCrList", "查询数据完成. DATA:insid" + (insId), CurrentThreadContext.getCurrentUserName());
		return lst;
	}
	
	/**
	 * 初始化授信关联产品列表
	 * @return
	 */
	@RequestMapping(value="/initPdList.do" ,method = {RequestMethod.GET})
	public @ResponseBody List<CrAstRltvInfoVO> initPdList(HttpServletRequest request, HttpServletResponse response) {
		String crid;
		crid = request.getParameter("crid");
		List<CrAstRltvInfoVO> crRlvLst = new ArrayList<CrAstRltvInfoVO>();
		if(crid == null || crid.trim().equals("")){
			return crRlvLst;
		}
		CrBaseInfoQueryCondition qc = new CrBaseInfoQueryCondition();
		qc.setCrIdQ(crid);
		CrBaseInfoVO crvo = crBaseInfoService.selectByCrId(crid);
		List<CrAstRltvInfoVO> crRlvLst2 = crvo.getCrAstRltvInfoListVO();
		for(CrAstRltvInfoVO vo : crRlvLst2){
			if(vo.getAstId() != null && !vo.getAstId().trim().equals("")){
				crRlvLst.add(vo);
			}else{
				logger.error("initPdList no pdid , crid is : "+crid);
			}
		}
		BaseLogUtils.info(logger, "initPdList", "查询数据完成. DATA:crid" + (crid), CurrentThreadContext.getCurrentUserName());
		return crRlvLst;
	}
	
	/**
	 * 初始化明细详情计费列表
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/initChrgList.do" ,method = {RequestMethod.GET})
	public @ResponseBody  Map<String, Object>  initChrgList(HttpServletRequest request, HttpServletResponse response) {
		String fncScmId = request.getParameter("fncScmId");
		Map<String, Object> map = new HashMap<String, Object>();
		List<ScmChrgParaVO> lstVO = new ArrayList<ScmChrgParaVO>();
		lstVO = scmBaseInfoService.selectChrgDataByScmId(Long.parseLong(fncScmId));
		map.put("Rows", lstVO);
		map.put("Total", lstVO.size());
		BaseLogUtils.info(logger, "initChrgList", "查询数据完成. DATA:fncScmId" + (fncScmId), CurrentThreadContext.getCurrentUserName());
		return map;
	}
	
	@RequestMapping(value="/modifyScmBscData.do" ,method = {RequestMethod.POST})
	public @ResponseBody Map<String, Object> modifyScmBscData(@RequestBody Object formdata) throws ParseException{
		Map<String, Object> map = new HashMap<String, Object>();
		JSONObject object = new JSONObject(); 
		Long fncScmId = (long) -1;
		if(formdata != null){
			object = JSONObject.fromObject(formdata);
			JSONArray grid1 = object.getJSONArray("griddata1");
			JSONArray formdata1 = object.getJSONArray("formdata");
			String rmrk = object.getString("rmrk");
			String guaranteeBody = object.getString("guaranteeBody");
			int cnt = validateAddForm(formdata1);
			map.put("nmcnt", 0);
			ScmBaseInfoVO vo = new ScmBaseInfoVO();
			try {
				for(int i=0;i<formdata1.size();i++){
					JSONObject objTmp = formdata1.getJSONObject(i);
					String key = objTmp.getString("name");
					String value = objTmp.getString("value");
					if(key.equals("bsFlotupRto")){
						if(StringUtils.isNotBlank(value)){
							vo.setBsFlotupRto(new BigDecimal(value).divide(new BigDecimal("100")));
						}
						continue;
					}else if(key.equals("cmtExrtSwp")){
						if(StringUtils.isNotBlank(value)){
							vo.setCmtExrtSwp(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("cmtIntrtSwp")){
						if(StringUtils.isNotBlank(value)){
							vo.setCmtIntrtSwp(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("crIdVal")){
						if(StringUtils.isNotBlank(value)){
							vo.setCrId(value);
						}
						continue;
					}else if(key.equals("dcnRate")){
						if(StringUtils.isNotBlank(value)){
							vo.setDcnRate(new BigDecimal(value).divide(new BigDecimal("100")));
						}
						continue;
					}else if(key.equals("stdt")){
						if(StringUtils.isNotBlank(value)){
							vo.setStdt(DateUtils.parseDate(value, "yyyy-MM-dd"));
						}
						continue;
					}else if(key.equals("eddt")){
						if(StringUtils.isNotBlank(value)){
							vo.setEddt(DateUtils.parseDate(value, "yyyy-MM-dd"));
						}
						continue;
					}else if(key.equals("exrtRskCntr")){
						if(StringUtils.isNotBlank(value)){
							vo.setExrtRskCntr(value);
						}
						continue;
					}else if(key.equals("exrtSwpBnk")){
						if(StringUtils.isNotBlank(value)){
							vo.setExrtSwpBnk(value);
						}
						continue;
					}else if(key.equals("exrtSwpFeert")){
						if(StringUtils.isNotBlank(value)){
							vo.setExrtSwpFeert(new BigDecimal(value).divide(new BigDecimal("100")));
						}
						continue;
					}else if(key.equals("exstExrtRsk")){
						if(StringUtils.isNotBlank(value)){
							vo.setExstExrtRsk(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("exstIntrtRsk")){
						if(StringUtils.isNotBlank(value)){
							vo.setExstIntrtRsk(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("fncCrdnlt")){
						if(StringUtils.isNotBlank(value)){
							vo.setFncCrdnlt(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("fncInsId")){
						vo.setFncInsId(Long.parseLong(value));
						continue;
					}else if(key.equals("fncIntrtTot")){
						if(StringUtils.isNotBlank(value)){
							vo.setFncIntrtTot(new BigDecimal(value).divide(new BigDecimal("100")));
						}
						continue;
					}else if(key.equals("fncScmNm")){
						vo.setFncScmNm(value.trim());
						continue;
					}else if(key.equals("fncTrm")){
						vo.setFncTrm(Integer.parseInt(value));
						continue;
					}else if(key.equals("intrtRskCntr")){
						if(StringUtils.isNotBlank(value)){
							vo.setIntrtRskCntr(value);
						}
						continue;
					}else if(key.equals("intrtSwpBnk")){
						if(StringUtils.isNotBlank(value)){
							vo.setIntrtSwpBnk(value);
						}
						continue;
					}else if(key.equals("intrtSwpFeert")){
						if(StringUtils.isNotBlank(value)){
							vo.setIntrtSwpFeert(new BigDecimal(value).divide(new BigDecimal("100")));
						}
						continue;
					}else if(key.equals("irr")){
						if(StringUtils.isNotBlank(value)){
							vo.setIrr(new BigDecimal(value).divide(new BigDecimal("100")).toString());
						}
						continue;
					}else if(key.equals("irtBs")){
						if(StringUtils.isNotBlank(value)){
							vo.setIrtBs(new BigDecimal(value).divide(new BigDecimal("100")));
						}
						continue;
					}else if(key.equals("mrgnClCrdnlt")){
						if(StringUtils.isNotBlank(value)){
							vo.setMrgnClCrdnlt(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("mrgnPct")){
						if(StringUtils.isNotBlank(value)){
							vo.setMrgnPct(new BigDecimal(value).divide(new BigDecimal("100")));
						}
						continue;
					}else if(key.equals("mrgnUseMtd")){
						if(StringUtils.isNotBlank(value)){
							vo.setMrgnUseMtd(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("pdIdVal")){
						if(StringUtils.isNotBlank(value)){
							vo.setPdId(value);
						}
						continue;
					}else if(key.equals("prymMtd")){
						if(StringUtils.isNotBlank(value)){
							vo.setPrymMtd(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("rePyTpCd")){
						vo.setRepyTp(Integer.parseInt(value));
						continue;
					}else if(key.equals("fncScmId")){
						vo.setFncScmId(Long.parseLong(value));
						fncScmId = Long.parseLong(value);
						continue;
					}
					else if(key.equals("mrgnWthrInPay")){
						if(StringUtils.isNotBlank(value)){
							vo.setMrgnWthrInPay(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("wthrFstPay")){
						if(StringUtils.isNotBlank(value)){
							vo.setWthrFstPay(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("irtTpcd")){
						if(StringUtils.isNotBlank(value)){
							vo.setIrtTpcd(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("wthrSupAbr")){
						if(StringUtils.isNotBlank(value)){
							vo.setWthrSupAbr(Integer.parseInt(value));
						}
					}else if(key.equals("busType")){
						if(StringUtils.isNotBlank(value)){
							vo.setBusType(value);
						}
					}else if(key.equals("scmIntrt")){
						if(StringUtils.isNotBlank(value)){
							vo.setScmIntrt(new BigDecimal(value).divide(new BigDecimal("100")));//
						}
						continue;
					}else if(key.equals("intrtMtdcd")){
						if(StringUtils.isNotBlank(value)){
							vo.setIntrtMtdcd(Integer.parseInt(value));//
						}
						continue;
					}//add by gengchunlan 20191021
					else if(key.equals("isGuarantee")){
						if(StringUtils.isNotBlank(value)){
							vo.setIsGuarantee(Long.parseLong(value));//
						}
						continue;
					}else if(key.equals("guaranteeStart")){
						vo.setGuaranteeStart(value);
						continue;
					}else if(key.equals("guaranteeEnd")){
						vo.setGuaranteeEnd(value);
						continue;
					}else if(key.equals("guaranteeRemark")){
						vo.setGuaranteeRemark(value);
						continue;
					}//end by gengchunlan 20191021                          
				}
				ScmBaseInfoVO bscinfo = scmBaseInfoService.selectById(fncScmId);
				if(bscinfo.getFncScmNm()!=null && !bscinfo.getFncScmNm().trim().equalsIgnoreCase(vo.getFncScmNm().trim()) && cnt>0){
					map.put("nmcnt", 1);
					return map;//修改方案时，排除原方案名称已存在
				}
				vo.setUptPsn(CurrentThreadContext.getCurrentUserId()+"");
				vo.setUpdTm(new Date());
				vo.setRmrk(rmrk);
				vo.setGuaranteeBody(guaranteeBody);
				scmBaseInfoService.modify(vo);
				map.put("id", fncScmId);
			} catch (Exception e) {
				map.put("result", e.getMessage());
				BaseLogUtils.error(logger, "modifyScmBscData", "异常:"+object.toString(), e);
				e.printStackTrace();
			}
			try{
				List<ScmChrgParaVO> chrgLst = new ArrayList<ScmChrgParaVO>();
				scmBaseInfoService.deleteChrgDataByScmId(fncScmId);
				for(int i=0;i<grid1.size();i++){
					JSONObject gobj = grid1.getJSONObject(i);
					if(gobj.has("costNm")){
						ScmChrgParaVO chrgVO = new ScmChrgParaVO();
						chrgVO.setFncScmId(fncScmId);
						chrgVO.setChrgTpCd(1);//融资端费用
						chrgVO.setCostNm(gobj.getString("costNm"));
						if(gobj.has("costPct")){
							chrgVO.setCostPct(new BigDecimal(gobj.getString("costPct") == null || gobj.getString("costPct").trim().equals("")  ? 
									"0": gobj.getString("costPct")).divide(new BigDecimal("100")));
						}else{
							chrgVO.setCostPct(new BigDecimal(0));
						}
						if(gobj.has("costAmt")){
							if(gobj.getString("costAmt") == null || "null".equals(gobj.getString("costAmt"))){
								chrgVO.setCostAmt(new BigDecimal(0));
							}else{
								chrgVO.setCostAmt(new BigDecimal(gobj.getString("costAmt") == null || gobj.getString("costAmt").trim().equals("") ? "0": gobj.getString("costAmt")));
							}
						}else{
							chrgVO.setCostAmt(new BigDecimal(0));
						}
						if(gobj.has("prePayDate")){
							if(StringUtils.isNotEmpty(gobj.getString("prePayDate")) && !gobj.getString("prePayDate").equals("null")
									&& gobj.getString("prePayDate").length()>0){
								if(gobj.getString("prePayDate").contains("-")){
									String prePayDate = gobj.getString("prePayDate").substring(0, 10);
									chrgVO.setPrePayDate(DateUtils.parseDate(prePayDate, "yyyy-MM-dd"));
								}else{
									long millionSeconds = Long.parseLong(gobj.getString("prePayDate"));//毫秒
									// 毫秒转日期
									Calendar c = Calendar.getInstance();
									c.setTimeInMillis(millionSeconds); 
									Date date = c.getTime();									
									chrgVO.setPrePayDate(date);
								}
							}
						}else{
							chrgVO.setPrePayDate(null);
						}
						if(gobj.has("costInTpCd")){
							chrgVO.setCostInTpCd(Integer.parseInt(gobj.getString("costInTpCd") == null ? "0": gobj.getString("costInTpCd")));
						}else{
							chrgVO.setCostInTpCd(2);
						}
						if(gobj.has("rmrk") && StringUtils.isNotBlank(gobj.getString("rmrk")) && !"null".equals(gobj.getString("rmrk"))){
							chrgVO.setRmrk(gobj.getString("rmrk"));
						}else{
							chrgVO.setRmrk("");
						}
						if(gobj.has("wthrDdct")){
							chrgVO.setWthrDdct(Integer.parseInt(gobj.getString("wthrDdct") == null ? "0": gobj.getString("wthrDdct")));
						}else{
							chrgVO.setWthrDdct(0);
						}//add 是否保证金 保证金到期处理方式  by gengchunlan 20180705
						if(gobj.has("mrgnIs")){//是否保证金 1是  0 否
							if(gobj.getString("mrgnIs")!=null && !"".equals(gobj.getString("mrgnIs")) && !"null".equals(gobj.getString("mrgnIs"))){
								chrgVO.setMrgnIs(Integer.parseInt(gobj.getString("mrgnIs")));
							}else{
							chrgVO.setMrgnIs(0);
							}
						}else{
							chrgVO.setMrgnIs(0);
						}
						if(gobj.has("mrgnUseMtd")){//保证金到期处理方式
							if(gobj.getString("mrgnUseMtd")!=null && !"".equals(gobj.getString("mrgnUseMtd")) && !"null".equals(gobj.getString("mrgnUseMtd"))){
								chrgVO.setMrgnUseMtd(Integer.parseInt(gobj.getString("mrgnUseMtd") == null ? "0": gobj.getString("mrgnUseMtd")));
							}else{
								chrgVO.setMrgnUseMtd(0);
							}
						}else{
							chrgVO.setMrgnUseMtd(0);
						}//end by gengchunlan 20180705
						chrgLst.add(chrgVO);
					}else{
						continue;
					}
				}
				if(chrgLst != null && chrgLst.size()>0){
					scmBaseInfoService.insertByBatch(chrgLst);
				}
				map.put("result", "0000");
			}catch (Exception e) {
				map.put("result", e.getMessage());
				BaseLogUtils.error(logger, "modifyScmBscDataChrg", "异常"+object.toString(), e);
				e.printStackTrace();
			}
		}
		return map;
	}
	
	@RequestMapping(value="/saveScmBscData.do" ,method = {RequestMethod.POST})
	public @ResponseBody Map<String, Object> saveScmBscData(@RequestBody Object formdata) throws ParseException{
		Map<String, Object> map = new HashMap<String, Object>();
		JSONObject object = new JSONObject(); 
		Long fncSmcId = Long.valueOf(-1);
		if(formdata != null){
			object = JSONObject.fromObject(formdata);
			JSONArray grid1 = object.getJSONArray("griddata1");
			JSONArray formdata1 = object.getJSONArray("formdata");
			String rmrk = object.getString("rmrk");
			String guaranteeBody = object.getString("guaranteeBody");
			int cnt = validateAddForm(formdata1);
			map.put("nmcnt", cnt);
			if(cnt>0){
				return map;//方案名称已存在
			}
			ScmBaseInfoVO vo = new ScmBaseInfoVO();
			try {
				for(int i=0;i<formdata1.size();i++){
					JSONObject objTmp = formdata1.getJSONObject(i);
					String key = objTmp.getString("name");
					String value = objTmp.getString("value");
					if(key.equals("bsFlotupRto")){
						if(StringUtils.isNotBlank(value)){
							vo.setBsFlotupRto(new BigDecimal(value).divide(new BigDecimal("100")));
						}
						continue;
					}else if(key.equals("cmtExrtSwp")){
						if(StringUtils.isNotBlank(value)){
							vo.setCmtExrtSwp(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("cmtIntrtSwp")){
						if(StringUtils.isNotBlank(value)){
							vo.setCmtIntrtSwp(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("crId_val")){
						if(StringUtils.isNotBlank(value)){
							vo.setCrId(value);
						}
						continue;
					}else if(key.equals("dcnRate")){
						if(StringUtils.isNotBlank(value)){
							vo.setDcnRate(new BigDecimal(value).divide(new BigDecimal("100")));
						}
						continue;
					}else if(key.equals("stdt")){
						if(StringUtils.isNotBlank(value)){
							vo.setStdt(DateUtils.parseDate(value, "yyyy-MM-dd"));
						}
						continue;
					}else if(key.equals("eddt")){
						if(StringUtils.isNotBlank(value)){
							vo.setEddt(DateUtils.parseDate(value, "yyyy-MM-dd"));
						}
						continue;
					}else if(key.equals("exrtRskCntr")){
						if(StringUtils.isNotBlank(value)){
							vo.setExrtRskCntr(value);
						}
						continue;
					}else if(key.equals("exrtSwpBnk")){
						if(StringUtils.isNotBlank(value)){
							vo.setExrtSwpBnk(value);
						}
						continue;
					}else if(key.equals("exrtSwpFeert")){
						if(StringUtils.isNotBlank(value)){
							vo.setExrtSwpFeert(new BigDecimal(value).divide(new BigDecimal("100")));
						}
						continue;
					}else if(key.equals("exstExrtRsk")){
						if(StringUtils.isNotBlank(value)){
							vo.setExstExrtRsk(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("exstIntrtRsk")){
						if(StringUtils.isNotBlank(value)){
							vo.setExstIntrtRsk(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("fncCrdnlt")){
						if(StringUtils.isNotBlank(value)){
							vo.setFncCrdnlt(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("fncInsId")){
						vo.setFncInsId(Long.parseLong(value));
						continue;
					}else if(key.equals("fncIntrtTot")){
						if(StringUtils.isNotBlank(value)){
							vo.setFncIntrtTot(new BigDecimal(value).divide(new BigDecimal("100")));
						}
						continue;
					}else if(key.equals("fncScmNm")){
						vo.setFncScmNm(value.trim());
						continue;
					}else if(key.equals("fncTrm")){
						vo.setFncTrm(Integer.parseInt(value));
						continue;
					}else if(key.equals("intrtRskCntr")){
						if(StringUtils.isNotBlank(value)){
							vo.setIntrtRskCntr(value);
						}
						continue;
					}else if(key.equals("intrtSwpBnk")){
						if(StringUtils.isNotBlank(value)){
							vo.setIntrtSwpBnk(value);
						}
						continue;
					}else if(key.equals("intrtSwpFeert")){
						if(StringUtils.isNotBlank(value)){
							vo.setIntrtSwpFeert(new BigDecimal(value).divide(new BigDecimal("100")));
						}
						continue;
					}else if(key.equals("irr")){
						if(StringUtils.isNotBlank(value)){
							vo.setIrr(new BigDecimal(value).divide(new BigDecimal("100")).toString());
						}
						continue;
					}else if(key.equals("irtBs")){
						if(StringUtils.isNotBlank(value)){
							vo.setIrtBs(new BigDecimal(value).divide(new BigDecimal("100")));
						}
						continue;
					}else if(key.equals("mrgnClCrdnlt")){
						if(StringUtils.isNotBlank(value)){
							vo.setMrgnClCrdnlt(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("mrgnPct")){
						if(StringUtils.isNotBlank(value)){
							vo.setMrgnPct(new BigDecimal(value).divide(new BigDecimal("100")));
						}
						continue;
					}else if(key.equals("mrgnUseMtd")){
						if(StringUtils.isNotBlank(value)){
							vo.setMrgnUseMtd(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("pdId_val")){
						if(StringUtils.isNotBlank(value)){
							vo.setPdId(value);
						}
						continue;
					}else if(key.equals("prymMtd")){
						if(StringUtils.isNotBlank(value)){
							vo.setPrymMtd(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("rePyTpCd")){
						vo.setRepyTp(Integer.parseInt(value));
						continue;
					}
					else if(key.equals("mrgnWthrInPay")){
						if(StringUtils.isNotBlank(value)){
							vo.setMrgnWthrInPay(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("wthrFstPay")){
						if(StringUtils.isNotBlank(value)){
							vo.setWthrFstPay(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("irtTpcd")){
						if(StringUtils.isNotBlank(value)){
							vo.setIrtTpcd(Integer.parseInt(value));
						}
						continue;
					}else if(key.equals("wthrSupAbr")){
						if(StringUtils.isNotBlank(value)){
							vo.setWthrSupAbr(Integer.parseInt(value));
						}
					}else if(key.equals("busType")){
						if(StringUtils.isNotBlank(value)){
							vo.setBusType(value);
						}
					}else if(key.equals("scmIntrt")){
						if(StringUtils.isNotBlank(value)){
							vo.setScmIntrt(new BigDecimal(value).divide(new BigDecimal("100")));//
						}
						continue;
					}else if(key.equals("intrtMtdcd")){
						if(StringUtils.isNotBlank(value)){
							vo.setIntrtMtdcd(Integer.parseInt(value));//
						}
						continue;
					}//add by gengchunlan 20191021
					else if(key.equals("isGuarantee")){
						if(StringUtils.isNotBlank(value)){
							vo.setIsGuarantee(Long.parseLong(value));//
						}
						continue;
					}else if(key.equals("guaranteeStart")){
						if(StringUtils.isNotBlank(value)){
							vo.setGuaranteeStart(value);//
						}
						continue;
					}else if(key.equals("guaranteeEnd")){
						if(StringUtils.isNotBlank(value)){
							vo.setGuaranteeEnd(value);//
						}
						continue;
					}else if(key.equals("guaranteeRemark")){
						if(StringUtils.isNotBlank(value)){
							vo.setGuaranteeRemark(value);//
						}
						continue;
					}//end by gengchunlan 20191021 
				}
				vo.setScmSt(1);
				vo.setIsDel(0);
				vo.setIsValid(1);
				vo.setGuaranteeBody(guaranteeBody);
				vo.setRmrk(rmrk);
				vo.setCrtPsn(CurrentThreadContext.getCurrentUserId()+"");
				vo.setCrtTm(new Date());
				fncSmcId = scmBaseInfoService.add(vo);
			} catch (Exception e) {
				BaseLogUtils.error(logger, "saveScmBscData", "异常"+object.toString(), e);
				e.printStackTrace();
			}
			if(fncSmcId != null && fncSmcId != -1){
				List<ScmChrgParaVO> chrgLst = new ArrayList<ScmChrgParaVO>();
				try {
					for(int i=0;i<grid1.size();i++){
						JSONObject gobj = grid1.getJSONObject(i);
						if(gobj.has("costNm")){
							ScmChrgParaVO chrgVO = new ScmChrgParaVO();
							chrgVO.setFncScmId(fncSmcId);
							chrgVO.setChrgTpCd(1);//融资端费用
							chrgVO.setCostNm(gobj.getString("costNm"));
							if(gobj.has("costPct")){
								chrgVO.setCostPct(new BigDecimal(gobj.getString("costPct") == null || gobj.getString("costPct").trim().equals("")  ? 
										"0": gobj.getString("costPct")).divide(new BigDecimal("100")));
							}else{
								chrgVO.setCostPct(new BigDecimal(0));
							}
							if(gobj.has("costAmt")){
								chrgVO.setCostAmt(new BigDecimal(gobj.getString("costAmt") == null || gobj.getString("costAmt").trim().equals("") ? "0": gobj.getString("costAmt")));
							}else{
								chrgVO.setCostAmt(new BigDecimal(0));
							}
							if(gobj.has("prePayDate")){
								if(StringUtils.isNotEmpty(gobj.getString("prePayDate")) && !gobj.getString("prePayDate").equals("null")
										&& gobj.getString("prePayDate").length()>0){
									String prePayDate = gobj.getString("prePayDate").substring(0, 10);//
									chrgVO.setPrePayDate(DateUtils.parseDate(prePayDate, "yyyy-MM-dd"));
								}
							}else{
								chrgVO.setPrePayDate(null);
							}
							if(gobj.has("costInTpCd")){
								chrgVO.setCostInTpCd(Integer.parseInt(gobj.getString("costInTpCd") == null ? "0": gobj.getString("costInTpCd")));
							}else{
								chrgVO.setCostInTpCd(2);
							}
							if(gobj.has("rmrk") && StringUtils.isNotBlank(gobj.getString("rmrk")) && !"null".equals(gobj.getString("rmrk"))){
								chrgVO.setRmrk(gobj.getString("rmrk"));
							}else{
								chrgVO.setRmrk("");
							}
							if(gobj.has("wthrDdct")){
								chrgVO.setWthrDdct(Integer.parseInt(gobj.getString("wthrDdct") == null ? "0": gobj.getString("wthrDdct")));
							}else{
								chrgVO.setWthrDdct(0);
							}
							//add 是否保证金 保证金到期处理方式  by gengchunlan 20180705
							if(gobj.has("mrgnIs")){//是否保证金 1是  0 否
								if(gobj.getString("mrgnIs")!=null && !"".equals(gobj.getString("mrgnIs")) && !"null".equals(gobj.getString("mrgnIs"))){
									chrgVO.setMrgnIs(Integer.parseInt(gobj.getString("mrgnIs")));
								}else{
									chrgVO.setMrgnIs(0);
								}
							}else{
								chrgVO.setMrgnIs(0);
							}
							if(gobj.has("mrgnUseMtd")){//保证金到期处理方式
								if(gobj.getString("mrgnUseMtd")!=null && !"".equals(gobj.getString("mrgnUseMtd")) && !"null".equals(gobj.getString("mrgnUseMtd"))){
									chrgVO.setMrgnUseMtd(Integer.parseInt(gobj.getString("mrgnUseMtd") == null ? "0": gobj.getString("mrgnUseMtd")));
								}else{
									chrgVO.setMrgnUseMtd(0);
								}
							}else{
								chrgVO.setMrgnUseMtd(0);
							}//end by gengchunlan 20180705
							chrgLst.add(chrgVO);
						}else{
							continue;
						}
					}
				} catch (Exception e) {
					BaseLogUtils.error(logger, "saveScmBscDataChrg", "异常"+object.toString(), e);
					e.printStackTrace();
				}
				if(chrgLst != null && chrgLst.size()>0){
					scmBaseInfoService.insertByBatch(chrgLst);
				}
			}
		}
		map.put("result", fncSmcId);
		return map;
	}
	
	/**
	 * 启动流程
	 */
	@RequestMapping(value = "/addFlowStart.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object addFlowStart(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		String procDefKey = request.getParameter("procDefKey");
		String procDefId = request.getParameter("procDefId");
		String procNo = request.getParameter("procNo");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "addFlowStart", SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY, CurrentThreadContext.getCurrentUserName());
			return result;
		}
		FlowStartParamsDTO flowStartParamsDTO = new FlowStartParamsDTO();
		try {
			//流程定义Key和流程定义ID 如果是前端选择的则直接指定,如果不是则系统自动按照配置选择唯一一条记录,如果找不到会提示
			flowStartParamsDTO.setAudStsCd(FlowConstant.FLOW_CHECK_STATE_IN);
			flowStartParamsDTO.setWordsInTheTable(ScmInfoConstant.SCM_FLOW_RSCM);
			flowStartParamsDTO.setProcDefKey(procDefKey);
			flowStartParamsDTO.setProcDefId(procDefId);
			flowStartParamsDTO.setProcNo(procNo);
			flowStartParamsDTO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
			flowStartParamsDTO.setBusinessKey(id);
			flowStartParamsDTO.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
			flowStartParamsDTO.setBuOrgCd(CurrentThreadContext.getCurrentBuOrgCd());
			flowStartParamsDTO.setSysCd(CurrentThreadContext.getCurrentSysCd());
			flowStartParamsDTO.setInitiator(String.valueOf(CurrentThreadContext.getCurrentUserId()));
			flowStartParamsDTO.setInitiatorNm(CurrentThreadContext.getCurrentUserName());
			flowStartParamsDTO.setProcPriority(FlowConstant.FLOW_PRIORITY_EMERGENCY);//优先级,可以在界面定义
			flowStartParamsDTO.setBusinessType(ScmInfoConstant.FLOW_BUSINESS_TYP_FNC_SCM_BSC_INFO);//确认用不用
			flowStartParamsDTO.setModelTyp(ScmInfoConstant.FLOW_MODEL_TYP_SCM_1);//需要和流程配置中的模块类型匹配
			flowStartParamsDTO.setSearchDesc(CurrentThreadContext.getCurrentOrgDispNm()+"、融资方案流程大字段参数未定!");
			DataResultDTO dataResultDTO = scmBaseInfoService.addFlowStart(flowStartParamsDTO);
			if(!dataResultDTO.getCode().equals(BaseExceptionConstant.BASE_EXCEPTION_CODE_200)){
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
			}
			if(null!=dataResultDTO && null!=dataResultDTO.getData()){
				FlowStartedDTO flowStartedDTO = (FlowStartedDTO) dataResultDTO.getData();
				if(StringUtils.isNotBlank(flowStartedDTO.getNextOperUsrNames())){
	                result.setInfo("下一个节点操作人:"+flowStartedDTO.getNextOperUsrNames());
	            }else{
	                result.setInfo("流程发起成功");
	            }
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(e.getMessage());
			BaseLogUtils.info(logger, "addFlowStart", "错误[BaseException],请求参数：" + JSONObject.fromObject(flowStartParamsDTO).toString() + " -ERROR:" +e.getMessage(), CurrentThreadContext.getCurrentUserName());
			e.getStackTrace();
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.error(logger, "addFlowStart", "错误[Exception],请求参数：" + JSONObject.fromObject(flowStartParamsDTO).toString() + " -ERROR:" +e.getMessage(), CurrentThreadContext.getCurrentUserName());
			e.getStackTrace();
		}
		return result;
	}

	@RequestMapping(value="/initCost1List.do" ,method = {RequestMethod.GET})
	public @ResponseBody List<KeyValueVO> initCost1List(HttpServletRequest request, HttpServletResponse response) {
		List<KeyValueVO> keyValLst = new ArrayList<KeyValueVO>();
		keyValLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_CHRG_PARM_FNC_CHRG_TPCD, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//融资端费用类型 费用名称
		return keyValLst;
	}

	@RequestMapping(value="/initCost2List.do" ,method = {RequestMethod.GET})
	public @ResponseBody List<KeyValueVO> initCost2List(HttpServletRequest request, HttpServletResponse response) {
		List<KeyValueVO> keyValLst = new ArrayList<KeyValueVO>();
		keyValLst = sysDictionaryApiService.getKvList(ScmInfoConstant.FNC_SCM_CHRG_PARM_OTHR_CHRG_TPCD, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());//其他费用类型 费用名称
		return keyValLst;
	}

	@RequestMapping(value = "/cancelData.do", method = { RequestMethod.POST})
	@ResponseBody
	public Object cancelData(HttpServletRequest request, HttpServletResponse response) {
		String id = request.getParameter("id");
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
		if(StringUtils.isEmpty(id)){
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
			BaseLogUtils.info(logger, "cancelData", SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY, CurrentThreadContext.getCurrentUserName());
			return result;
		}
		try {
			ScmBaseInfoVO entity = new ScmBaseInfoVO();
			entity.setFncScmId(Long.parseLong(id));
			entity.setScmSt(ScmSt.NOUSE.getKey());
			scmBaseInfoService.modify(entity);
		} catch (Exception e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
			BaseLogUtils.info(logger, "cancelData", SysLogConstant.LOG_CMM_SYS_ERROR, CurrentThreadContext.getCurrentUserName());
			e.printStackTrace();
		}
		return result;
	}
	
	//验证提交表单
	public int validateAddForm(JSONArray formdata){
		try {
			for(int i=0;i<formdata.size();i++){
				JSONObject objTmp = formdata.getJSONObject(i);
				String key = objTmp.getString("name");
				String value = objTmp.getString("value");

				ScmBaseInfoQueryCondition cnd = new ScmBaseInfoQueryCondition();
				if(key.equals("fncScmNm")){
					if(value!=null && !value.trim().equals("")){
						cnd.setFncScmNm(value.trim());						
						int cnt = scmBaseInfoService.selectExistScmCntByCondition(cnd);
						if(cnt > 0){
							return cnt;
						}
					}
				}
			}
		} catch (Exception e) {
			BaseLogUtils.error(logger, "validateAddForm", "异常", e);
			e.printStackTrace();
			return -1;
		}		
		return 0;
	}
}
